<!-- 导航栏 -->
<template>
    <div>
        <div class="recruit_top_right">
            <div class="flex">
                <div class="h100 recruit_top_navs flex flex_c jcc aic"
                    :class="state.navValue == item.id ? 'recruit_top_nav' : ''" v-for="(item, index) in state.dataList"
                    :key="index">
                    <div class="flex flex_c jcc aic" @click="navClick(item)">
                        <!-- <p class="fonts24">{{ item.value }}</p> -->
                        <p class="fonts18 fontw500" style="margin-top: 10px;">{{ item.label }}</p>
                    </div>
                    <el-dropdown style="width: 100%;margin-top: 10px;" trigger="click">
                        <span class="el-dropdown-link flex jcsb" style="width: 80%;margin: auto;">
                            <span :class="state.navValue == item.id ? 'colorwrite' : ''">{{
                                item.valueLable ? item.valueLable : "请选择" }}</span>
                            <el-icon class="el-icon--right" :color="state.navValue == item.id ? '#ffffff' : ''">
                                <arrow-down />
                            </el-icon>
                        </span>
                        <template #dropdown>
                            <el-dropdown-menu>
                                <el-dropdown-item @click="Labelclick(item, items,indexs)" :key="indexs"
                                    v-for="(items, indexs) in item.labelData">{{ items.label }}</el-dropdown-item>
                            </el-dropdown-menu>
                        </template>
                    </el-dropdown>
                </div>
            </div>
        </div>
    </div>
</template>
<script setup lang="tsx">
import { positionRegistration } from "@/api/home/index";
import { reactive, onMounted, ref, watch } from "vue"
const emit = defineEmits(['headerClick'])
const props = defineProps({
    refresh: {
        type: Boolean,
        default: () => {
            return false
        }
    }
})
const loading = ref(false)
const state = reactive({
    navValue: 0,
    labelValue: "",
    dataList: [
        {
            label: "初筛",
            value: 0,
            statusLe: "",
            statusGe: "",
            id: 0,
            valueLable: "",
            values: "0",
            labelData: [
                {
                    label: "全部",
                    statusIn:"1,-1",
                    
                },
                {
                    label: "待筛选",
                    statusIn:"1",
                   
                },
                {
                    label: "通过",
                    statusGe: "2",
                   
                },
                {
                    label: "未通过",
                    statusIn: "-1",
                 
                },
                {
                    label: "待定",
                    statusIn: "1",
                    initialScreeningUnqualifiedLabel:"13",
                  
                },
                
            ]
        }, {
            label: "应聘部门筛选",
            value: 0,
            statusLe: "",
            statusGe: "",
            id: 1,
            valueLable: "",
            values: "0",
            labelData: [
            {
                    label: "全部",
                    statusIn:"2,-2"
                },
                {
                    label: "待筛选",
                    statusIn:"2"
                },
                {
                    label: "通过",
                    statusGe: "3"
                },
                {
                    label: "未通过",
                    statusIn: "-2"
                },
                {
                    label: "待定",
                    statusIn: "2",
                    initialScreeningUnqualifiedLabel:"13"
                },
                
            ]
        }, {
            label: "笔试",
            value: 0,
            statusLe: "",
            statusGe: "",
            id: 2,
            valueLable: "",
            values: "0",
            labelData: [
            {
                    label: "全部",
                    statusIn:"3,-3"
                },
                {
                    label: "待筛选",
                    statusIn:"3"
                },
                {
                    label: "通过",
                    statusGe: "4"
                },
                {
                    label: "未通过",
                    statusIn: "-3"
                },
                {
                    label: "待定",
                    statusIn: "3",
                    initialScreeningUnqualifiedLabel:"13"
                },
                
            ]
        }, {
            label: "面试",
            value: 0,
            statusLe: "",
            statusGe: "",
            id: 3,
            valueLable: "",
            values: "0",
            labelData: [
            {
                    label: "全部",
                    statusIn:"4,-4"
                },
                {
                    label: "待筛选",
                    statusIn:"4"
                },
                {
                    label: "通过",
                    statusGe: "5"
                },
                {
                    label: "未通过",
                    statusIn: "-4"
                },
                {
                    label: "待定",
                    statusIn: "4",
                    initialScreeningUnqualifiedLabel:"13"
                },
                
            ]
        }, {
            label: "体检审查",
            value: 0,
            statusLe: "",
            statusGe: "",
            id: 4,
            valueLable: "",
            values: "0",
            labelData: [
            {
                    label: "全部",
                    statusIn:"5,6,7,-5,-6,-7"
                },
                {
                    label: "待筛选",
                    statusIn:"5,6,7"
                },
                {
                    label: "通过",
                    statusGe: "8"
                },
                {
                    label: "未通过",
                    statusIn: "-5,-6,-7"
                },
                {
                    label: "待定",
                    statusIn: "5,6,7",
                    initialScreeningUnqualifiedLabel:"13"
                },
               
            ]
        }, {
            label: "待入职",
            value: 0,
            statusLe: "",
            statusGe: "",
            id: 5,
            valueLable: "",
            values: "0",
            labelData: [
            {
                    label: "全部",
                    statusIn:"8,-8"
                },
                {
                    label: "待筛选",
                    statusIn:"8"
                },
                {
                    label: "通过",
                    statusGe: "-9"
                },
                {
                    label: "未通过",
                    statusIn: "-8"
                },
                {
                    label: "待定",
                    statusIn: "8",
                    initialScreeningUnqualifiedLabel:"13"
                },
                
            ]
        },
    ],
})
const Labelclick = (item, items,indexs) => {
    item.valueLable = items.label
    item.values = indexs
    sessionStorage.setItem("headerValue",JSON.stringify(item))
    emit('headerClick', item)
}
watch(() => props.refresh, (newValue: any) => {
    console.log("刷新", newValue);
    positionRegistrationApi()
})
onMounted(() => {
})


const navClick = (item) => {
    state.navValue = item.id
    sessionStorage.setItem("asideValue","0")
    sessionStorage.setItem("headerValue",JSON.stringify(item))
    emit('headerClick', item)
}
const positionRegistrationApi = async () => {//表头
    loading.value = true
    await positionRegistration().then(res => {
        // console.log("表头信息:", res.data);
        // state.headerData = res.data
        loading.value = false
        // 初筛
        state.dataList[0].value = `${res.data.initialScreening}`
        state.dataList[0].labelData[0].label = `全部(${res.data.initialScreening+res.data.notPassedInitialScreening})`
        state.dataList[0].labelData[1].label = `待筛选(${res.data.initialScreening})`
        state.dataList[0].labelData[3].label = `未通过(${res.data.notPassedInitialScreening})`
        // state.dataList[0].valueLable = `全部${res.data.initialScreening+res.data.notPassedInitialScreening}`
        state.dataList[0].statusLe = res.data.initialScreeningStatusLe
        state.dataList[0].statusGe = res.data.initialScreeningStatusGe
        state.dataList[0].valueLable = `全部(${res.data.initialScreening+res.data.notPassedInitialScreening})`

        // 应聘部门筛选
        state.dataList[1].value = res.data.department
        state.dataList[1].labelData[0].label = `全部(${res.data.department+res.data.notPassedDepartment})`
        state.dataList[1].labelData[1].label = `待筛选(${res.data.department})`
        state.dataList[1].labelData[3].label = `未通过(${res.data.notPassedDepartment})`
        state.dataList[1].statusLe = res.data.departmentStatusLe
        state.dataList[1].statusGe = res.data.departmentStatusGe
        state.dataList[1].valueLable = `全部(${res.data.department+res.data.notPassedDepartment})`

        // 笔试
        state.dataList[2].value = res.data.writtenExamination
        state.dataList[2].labelData[0].label = `全部(${res.data.writtenExamination+res.data.notPassedWrittenExamination})`
        state.dataList[2].labelData[1].label = `待筛选(${res.data.writtenExamination})`
        state.dataList[2].labelData[3].label = `未通过(${res.data.notPassedWrittenExamination})`
        state.dataList[2].statusLe = res.data.writtenExaminationStatusLe
        state.dataList[2].statusGe = res.data.writtenExaminationStatusGe
        state.dataList[2].valueLable = `全部(${res.data.writtenExamination+res.data.notPassedWrittenExamination})`

        // 面试
        state.dataList[3].value = res.data.interview
        state.dataList[3].statusLe = res.data.interviewStatusLe
        state.dataList[3].statusGe = res.data.interviewStatusGe
        state.dataList[3].labelData[0].label = `全部(${res.data.interview+res.data.notPassedInterview})`
        state.dataList[3].labelData[1].label = `待筛选(${res.data.interview})`
        state.dataList[3].labelData[3].label = `未通过(${res.data.notPassedInterview})`
        state.dataList[3].valueLable = `全部(${res.data.interview+res.data.notPassedInterview})`

        // 体检审查
        state.dataList[4].value = res.data.medicalExaminationReview
        state.dataList[4].statusLe = res.data.medicalExaminationReviewStatusLe
        state.dataList[4].statusGe = res.data.medicalExaminationReviewStatusGe
        state.dataList[4].labelData[0].label = `全部(${res.data.medicalExaminationReview+res.data.notPassedMedicalExaminationReview})`
        state.dataList[4].labelData[1].label = `待筛选(${res.data.medicalExaminationReview})`
        state.dataList[4].labelData[3].label = `未通过(${res.data.notPassedMedicalExaminationReview})`
        state.dataList[4].valueLable = `全部(${res.data.medicalExaminationReview+res.data.notPassedMedicalExaminationReview})`

        // 待入职
        state.dataList[5].value = res.data.waitingForEntry
        state.dataList[5].statusLe = res.data.waitingForEntryStatusLe
        state.dataList[5].statusGe = res.data.waitingForEntryStatusGe
        state.dataList[5].labelData[0].label = `全部(${res.data.waitingForEntry+res.data.notPassedWaitingForEntry})`
        state.dataList[5].labelData[1].label = `待筛选(${res.data.waitingForEntry})`
        state.dataList[5].labelData[3].label = `未通过(${res.data.notPassedWaitingForEntry})`
        state.dataList[5].valueLable = `全部(${res.data.waitingForEntry+res.data.notPassedWaitingForEntry})`

        // 权限
        let datas = JSON.parse(sessionStorage.getItem("my_Info"))
        if (datas.roles[0] == "admin") {
        } else {
            state.dataList = state.dataList.slice(0, 2)
        }
        console.log("表头信息：", state.dataList);
        let obj:any=sessionStorage.getItem("headerValue")?JSON.parse(sessionStorage.getItem("headerValue")):""
        console.log("表头信息-----------------：",obj);
        if(obj){
            state.navValue=obj.id
            state.dataList[state.navValue].valueLable=state.dataList[state.navValue].labelData[obj.values].label
            state.dataList[state.navValue].values=obj.values 
        }
        sessionStorage.setItem("headerValue",JSON.stringify(state.dataList[state.navValue]))
        emit('headerClick', state.dataList[state.navValue])

    })
}
positionRegistrationApi()
</script>
<style scoped>
.el-dropdown-menu {
    width: 160px;
}

.example-showcase .el-dropdown-link {
    cursor: pointer;
    color: var(--el-color-primary);
    display: flex;
    align-items: center;
}

.colorwrite {
    color: #FFFFFF;
}
</style>
<style lang="less" scoped>
.recruit_top_right {
    width: 100%;
    background: #FFFFFF;
    height: 70px;
}

.recruit_top_navs {
    width: 160px;
    height: 70px;
    background: #FFFFFF;
    border-radius: 0px 0px 0px 0px;
    opacity: 1;
}

.recruit_top_nav {
    background: #2F6CBC;

    p {
        color: #FFFFFF;
    }
}
</style>